package hr.ctg.domain.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;

@Entity
@Name("objava")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Table(name = "objava")
@NamedQueries( {
		@NamedQuery(name = "Objava.findByIdTipaObjave", query = "select o from Objava o where o.tipObjave.idTipaObjave = ? order by o.datum desc"),
		@NamedQuery(name = "Objava.findByDatum", query = "select o from Objava o order by o.datum desc"),
		@NamedQuery(name = "Objava.findByIdTipaObjaveIdObjekta", query = "select o from Objava o where o.tipObjave.idTipaObjave = ? and o.objekt.idObjekta = ? order by o.datum desc"),
		@NamedQuery(name = "Objava.findByIdTipaObjaveIdMjesta", query = "select o from Objava o where o.tipObjave.idTipaObjave = ? and o.mjesto.idMjesta = ? order by o.datum desc"),
		@NamedQuery(name = "Objava.findByIdTipaObjaveIdOtoka", query = "select o from Objava o where o.tipObjave.idTipaObjave = ? and o.otok.idOtoka = ? order by o.datum desc"),
		@NamedQuery(name = "Objava.findByIdTipaObjaveIdParka", query = "select o from Objava o where o.tipObjave.idTipaObjave = ? and o.park.idParka = ? order by o.datum desc"),
		@NamedQuery(name = "Objava.findByIdKorisnika", query = "select o from Objava o where o.korisnik.idKorisnika = ? order by o.datum desc"),
		@NamedQuery(name = "Objava.findByIdObjekta", query = "select o from Objava o where o.korisnik.idKorisnika = ? order by o.tipObjave,o.datum desc"),
		@NamedQuery(name = "Objava.findByIdMjesta", query = "select o from Objava o where o.mjesto.idMjesta = ? order by o.tipObjave,o.datum desc"),
		@NamedQuery(name = "Objava.findByIdOtoka", query = "select o from Objava o where o.otok.idOtoka = ? order by o.tipObjave,o.datum desc"),
		@NamedQuery(name = "Objava.findByIdParka", query = "select o from Objava o where o.park.idParka = ? order by o.tipObjave,o.datum desc") })
public class Objava implements Serializable {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id_objave")
	private Integer idObjave;
	@NotNull
	@Length(max = 250)
	@Column(name = "tekst")
	private String tekst;
	@NotNull
	private String www;
	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_objekta")
	private Objekt objekt;
	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_mjesta")
	private Mjesto mjesto;
	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_otoka")
	private Otok otok;
	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_parka")
	private Park park;
	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_korisnika", nullable = false)
	@NotNull
	private Korisnik korisnik;
	@NotNull
	private Date datum;
	@NotNull
	@Length(max = 100)
	private String naslov;
	@NotNull
	@Length(max = 100)
	private String stranica;

	@ManyToOne
	@JoinColumn(name = "id_tipa_objave")
	private TipObjave tipObjave;

	private static final long serialVersionUID = 1L;

	public Objava() {
		super();
	}

	public Integer getIdObjave() {
		return idObjave;
	}

	public void setIdObjave(final Integer idObjave) {
		this.idObjave = idObjave;
	}

	public String getTekst() {
		return tekst;
	}

	public void setTekst(final String tekst) {
		this.tekst = tekst;
	}

	public String getWww() {
		return www;
	}

	public void setWww(final String www) {
		this.www = www;
	}

	public Date getDatum() {
		return datum;
	}

	public void setDatum(final Date datum) {
		this.datum = datum;
	}

	public void setKorisnik(final Korisnik korisnik) {
		this.korisnik = korisnik;
	}

	public Korisnik getKorisnik() {
		return korisnik;
	}

	public void setObjekt(final Objekt objekt) {
		this.objekt = objekt;
	}

	public Objekt getObjekt() {
		return objekt;
	}

	public void setMjesto(final Mjesto mjesto) {
		this.mjesto = mjesto;
	}

	public Mjesto getMjesto() {
		return mjesto;
	}

	public void setOtok(final Otok otok) {
		this.otok = otok;
	}

	public Otok getOtok() {
		return otok;
	}

	public void setPark(final Park park) {
		this.park = park;
	}

	public Park getPark() {
		return park;
	}

	public void setTipObjave(final TipObjave tipObjave) {
		this.tipObjave = tipObjave;
	}

	public TipObjave getTipObjave() {
		return tipObjave;
	}

	/**
	 * @param naslov
	 *            the naslov to set
	 */
	public void setNaslov(final String naslov) {
		this.naslov = naslov;
	}

	/**
	 * @return the naslov
	 */
	public String getNaslov() {
		return naslov;
	}

	/**
	 * @param stranica
	 *            the stranica to set
	 */
	public void setStranica(final String stranica) {
		this.stranica = stranica;
	}

	/**
	 * @return the stranica
	 */
	public String getStranica() {
		return stranica;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (idObjave == null ? 0 : idObjave.hashCode());
		return result;
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		final Objava other = (Objava) obj;
		if (idObjave == null) {
			if (other.idObjave != null) {
				return false;
			}
		} else if (!idObjave.equals(other.idObjave)) {
			return false;
		}
		return true;
	}

}
